package checkerView;

import java.awt.GridBagLayout;
import javax.swing.JPanel;

import java.awt.Button;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.BorderLayout;
import java.awt.TextField;

import javax.swing.JSplitPane;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;
import java.util.Iterator;
import java.util.TreeSet;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JMenuBar;
import javax.swing.JTextField;
import javax.swing.BoxLayout;
import javax.swing.JTabbedPane;
import javax.swing.JScrollPane;
import java.awt.Rectangle;
import javax.swing.JLabel;

import wcg.OutputTextArea;
import wcg.PanelSplineInterporation;
import wcg.PanelWinExporter;
import wcg.PanelwinFormatChecker;
import wcg.winchkgProp;
import wcg.winchkgProperty;
import winsplitter.PanelwinSplitter;

public class CheckerView extends JPanel implements TextListener  {

	private static final long serialVersionUID = 1L;
	private JSplitPane jSplitPaneStdOutErr = null;

	private OutputTextArea Out;
	private OutputTextArea Err;
	private int DisplayLevel=1;
	private boolean CheckInterFiles = true;
	private PanelwinFormatChecker jPanelwinFormatChecker = null;
	private PanelwinSplitter jPanelwinSplitter=null;
	private PanelWinExporter jPanelWinConveter=null;
	private PanelSplineInterporation jPanelSplineInterporation= null;
	private JTabbedPane jTabbedPaneTools = null;
	private JPanel jPanelStdOutErr = null;
	private JPanel jPanelNorth = null;
	private JButton jButtonClear = null;
	private JLabel jLabelTitle = null;
	private String OutputDir = null;  //  @jve:decl-index=0:
	private TextListener Parent = null;
	public void setParent(TextListener pa){
		Parent = pa;
	    Err.addTextListener(Parent);
	}
	public void setOutputDir(String dir){
		OutputDir=dir;
		getJPanelWinConverter().setOutDir(dir);
		getJPanelwinSplitter().setOutDir(dir);
	}
	public String getOutputDir(){
		return OutputDir;
		
	}
	
	public int getDisplayLevel() {
		return DisplayLevel;
	}

	public boolean isCheckInterFiles() {
		return CheckInterFiles;
	}

	public void setDisplayLevel(int displayLevel) {
		DisplayLevel = displayLevel;
	}

	public void setCheckInterFiles(boolean checkInterFiles) {
		CheckInterFiles = checkInterFiles;
	}

	/**
	 * This is the default constructor
	 */
	public CheckerView() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(600, 400);
		this.setLayout(new BorderLayout());
		this.add(getJTabbedPaneTools(), BorderLayout.NORTH);
		this.add(getJPanelStdOutErr(), BorderLayout.CENTER);  // Generated
	}

	/**
	 * This method initializes jSplitPaneStdOutErr	
	 * 	
	 * @return javax.swing.JSplitPane	
	 */
	private JSplitPane getJSplitPaneStdOutErr() {
		if (jSplitPaneStdOutErr == null) {
			//jSplitPaneStdOutErr = new JSplitPane();
		    Out = new OutputTextArea();
		    Out.setRows(3000);
		    Out.setForeground(Color.black);
		    Out.setToSystemOut();
		    Out.setMinimumSize(new Dimension(20,20));
		    Out.setPreferredSize(new Dimension(400, 200));
		    Out.setBackground(Color.white);
		    Err = new OutputTextArea();
		    Err.setRows(3000);
		    Err.setForeground(Color.red);
		    Err.setToSystemErr();
		    Err.setMinimumSize(new Dimension(20,20));
		    Err.setPreferredSize(new Dimension(50,200));
		    Err.setBackground(Color.white);
		    jSplitPaneStdOutErr = new JSplitPane();
		    jSplitPaneStdOutErr.setLeftComponent(Out);
		    jSplitPaneStdOutErr.setRightComponent(Err);
		    jSplitPaneStdOutErr.setMinimumSize(new Dimension(100,20));
		    jSplitPaneStdOutErr.setDoubleBuffered(true);
		}
		return jSplitPaneStdOutErr;
	}

	/**
	 * This method initializes jPanelwinFormatChecker	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelwinFormatChecker() {
		if (jPanelwinFormatChecker == null) {
			jPanelwinFormatChecker = new PanelwinFormatChecker();

			//jPanelwinFormatChecker.checkerView = this;
			//jPanelwinFormatChecker.setMinimumSize(new Dimension(100,300));
			//jPanelChecker.setSize(new Dimension(300,100));
		}
		return jPanelwinFormatChecker;
	}
	private PanelwinSplitter getJPanelwinSplitter() {
		if (jPanelwinSplitter == null) {
			jPanelwinSplitter = new PanelwinSplitter();
		}
		return jPanelwinSplitter;
	}
	private PanelWinExporter getJPanelWinConverter() {
		if (jPanelWinConveter == null) {
			jPanelWinConveter = new PanelWinExporter();
		}
		return jPanelWinConveter;
	}
	private PanelSplineInterporation getJPanelSplineInterporation(){
		if(jPanelSplineInterporation==null){
			jPanelSplineInterporation = new PanelSplineInterporation();
			jPanelSplineInterporation.mCheckerView = this;
		}
		return jPanelSplineInterporation;
	}
	/**
	 * This method initializes jTabbedPaneTools	
	 * 	
	 * @return javax.swing.JTabbedPane	
	 */
	private JTabbedPane getJTabbedPaneTools() {
		if (jTabbedPaneTools == null) {
			jTabbedPaneTools = new JTabbedPane();
			jTabbedPaneTools.setPreferredSize(new Dimension(400, 260));
			if(winchkgProperty.availableWincheker){
				jTabbedPaneTools.addTab("win checker", 
						new ImageIcon(getClass().getClassLoader().getResource("images/magnifier.png"))
						, getJPanelwinFormatChecker(), null);
			}
			//if(winchkgPropInst.EditionControl == winchkgPropInst.EditionControlFull){
			if(winchkgProperty.availableSplitter){
				jTabbedPaneTools.addTab("win splitter", 
						new ImageIcon(getClass().getClassLoader().getResource("images/page_white_stack.png"))
						, getJPanelwinSplitter(), null);
	
			}
			if(winchkgProperty.availableWinConverter){
					jTabbedPaneTools.addTab("win converter", 
						new ImageIcon(getClass().getClassLoader().getResource("images/page_refresh.gif"))
						, getJPanelWinConverter(), null);
			}
			
			if(winchkgProperty.availableSplineInterporation){
				jTabbedPaneTools.addTab("Spline Interporation", 
						new ImageIcon(getClass().getClassLoader().getResource("images/chart_line.png"))
						, getJPanelSplineInterporation(), null);
			}
			//}
				
		}
		return jTabbedPaneTools;
	}
	public void ResetContents(){
		Out.resetContent();
		Err.resetContent();
	}
	
	public void LoadSaveProperty(boolean save,winchkgProp prop){
		getJPanelSplineInterporation().LoadSaveProperty(save,prop);
	}

	/**
	 * This method initializes jPanelStdOutErr	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelStdOutErr() {
		if (jPanelStdOutErr == null) {
			jPanelStdOutErr = new JPanel();
			jPanelStdOutErr.setPreferredSize(new Dimension(200,200));
			jPanelStdOutErr.setLayout(new BorderLayout());  // Generated
			jPanelStdOutErr.add(getJPanelNorth(), BorderLayout.NORTH);  // Generated
			jPanelStdOutErr.add(getJSplitPaneStdOutErr(), BorderLayout.CENTER);  // Generated
		}
		return jPanelStdOutErr;
	}

	/**
	 * This method initializes jPanelNorth	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelNorth() {
		if (jPanelNorth == null) {
			jLabelTitle = new JLabel();
			jLabelTitle.setBounds(new Rectangle(5, 3, 114, 20));  // Generated
			jLabelTitle.setText("std out / std err");  // Generated
			jPanelNorth = new JPanel();
			jPanelNorth.setPreferredSize(new Dimension(200,26));
			jPanelNorth.setLayout(null);  // Generated
			jPanelNorth.add(getJButtonClear(), null);  // Generated
			jPanelNorth.add(jLabelTitle, null);  // Generated
		}
		return jPanelNorth;
	}

	/**
	 * This method initializes jButtonClear	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonClear() {
		if (jButtonClear == null) {
			jButtonClear = new JButton(new ImageIcon(CheckerView.class.getResource("/images/trashcan.png")));
			jButtonClear.setBounds(new Rectangle(127, 2, 22, 22));  // Generated
			jButtonClear.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					ResetContents();
				}
			});
		}
		return jButtonClear;
	}
	@Override
	public void textValueChanged(TextEvent e) {
		// std errに変更があった場合
		Object obj = e.getSource();
		if(obj instanceof OutputTextArea){
			OutputTextArea ta = (OutputTextArea)obj;//@
			String str = ta.getText();
		}
	}
	/**
	 * @param myMenuBar
	 */
	public void addMenu(JMenuBar myMenuBar) {
		
	}

	
}  //  @jve:decl-index=0:visual-constraint="264,83"


